package com.ruoyi.project.user.ioslog.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.user.ioslog.domain.IosLog;
import com.ruoyi.project.user.ioslog.service.IIosLogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * iOS上报Controller
 *
 * @author shixiangwen
 * @date 2022-12-01
 */
@Controller
@RequestMapping("/user/ioslog")
public class IosLogController extends BaseController {
    private String prefix = "user/ioslog";

    @Autowired
    private IIosLogService iosLogService;

    @RequiresPermissions("user:ioslog:view")
    @GetMapping()
    public String ioslog() {
        return prefix + "/ioslog";
    }

    /**
     * 查询iOS上报列表
     */
    @RequiresPermissions("user:ioslog:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IosLog iosLog) {
        startPage();
        List<IosLog> list = iosLogService.selectIosLogList(iosLog);
        return getDataTable(list);
    }

    /**
     * 导出iOS上报列表
     */
    @RequiresPermissions("user:ioslog:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IosLog iosLog) {
        List<IosLog> list = iosLogService.selectIosLogList(iosLog);
        ExcelUtil<IosLog> util = new ExcelUtil<IosLog>(IosLog.class);
        return util.exportExcel(list, "ioslog");
    }

    /**
     * 新增iOS上报
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存iOS上报
     */
    @RequiresPermissions("user:ioslog:add")
    @Log(title = "iOS上报", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IosLog iosLog) {
        return toAjax(iosLogService.insertIosLog(iosLog));
    }

    /**
     * 修改iOS上报
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        IosLog iosLog = iosLogService.selectIosLogById(id);
        mmap.put("iosLog", iosLog);
        return prefix + "/edit";
    }

    @RequiresPermissions("user:ioslog:detail")
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") Long id, ModelMap mmap) {
        mmap.put("iosLog", iosLogService.selectIosLogById(id));
        return prefix + "/detail";
    }

    /**
     * 修改保存iOS上报
     */
    @RequiresPermissions("user:ioslog:edit")
    @Log(title = "iOS上报", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IosLog iosLog) {
        return toAjax(iosLogService.updateIosLog(iosLog));
    }

    /**
     * 删除iOS上报
     */
    @RequiresPermissions("user:ioslog:remove")
    @Log(title = "iOS上报", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(iosLogService.deleteIosLogByIds(ids));
    }
}
